package com.elitel.frame.base.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.elitel.frame.main.entity.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.elitel.frame.base.component.exportprojectdata.DataBaseConnInfo;
import com.elitel.frame.base.service.SysLoginfoService;
import com.elitel.frame.main.dao.SysLoginfoMapper;
import com.elitel.frame.main.dao.ext.ExtSysLoginfoMapper;
import com.elitel.frame.main.entity.SysLoginfo;
import com.elitel.frame.main.entity.vo.PageRequestVo;
import com.elitel.frame.main.entity.vo.PageResponseVo;

/**
 * @author guoyanfei
 * @Description 日志信息服务实现类
 */
@Service
public class SysLoginfoServiceImpl implements SysLoginfoService {

    @Autowired
    private ExtSysLoginfoMapper extSysLoginfoMapper;

    @Autowired
    private SysLoginfoMapper sysLoginfoMapper;

    @Autowired
    private DataBaseConnInfo dataBaseConnInfo;

    @Override
    public PageResponseVo<SysLoginfo> getListByPage(PageRequestVo<SysLoginfo> pr) {
        String databaseType = dataBaseConnInfo.dataBaseType;
        List<SysLoginfo> list = new ArrayList<SysLoginfo>();
        if (databaseType.equals("oracle")) {
            pr.StartPage();
            list = extSysLoginfoMapper.getListByPage(pr);
        } else if (databaseType.equals("mysql") || databaseType.equals("sqlite")) {
            pr.setPageNo(pr.getPageNo() - 1);
            list = extSysLoginfoMapper.getListByPageMysql(pr);
        } else if (databaseType.equals(DataSourceType.POSTGRES)) {
            pr.setPageNo(pr.getPageNo() - 1);
            list = extSysLoginfoMapper.getListByPagePG(pr);
        }
        Integer total = extSysLoginfoMapper.getListCount(pr);
        PageResponseVo<SysLoginfo> responseVo = new PageResponseVo<SysLoginfo>();
        responseVo.setRows(list);
        responseVo.setTotal(total);
        return responseVo;
    }

    @Override
    public void cleanAllData() {
        extSysLoginfoMapper.cleanAllData();

    }

    @Override
    public Integer deleteDataByguids(String guids) {
        Integer result = 0;
        String[] guid = guids.split(",");
        for (String string : guid) {
            result += sysLoginfoMapper.deleteByPrimaryKey(string);
        }
        return result;
    }


}
